export function addr (name, maxLength) {
  if (!maxLength) {
    maxLength = 20
  }
  if (name == null || name.length < 1) {
    return ""
  }
  var w = 0;
  var s = 0;
  var p = false;
  var b = false;
  var nameSub;
  for (var i = 0; i < name.length; i++) {
    if (i > 1 && b == false) {
      p = false
    }
    if (i > 1 && b == true) {
      p = true
    }
    var c = name.charCodeAt(i);
    if ((c >= 1 && c <= 126) || (65376 <= c && c <= 65439)) {
      w++;
      b = false
    } else {
      w += 2;
      s++;
      b = true
    }
    if (w > maxLength && i <= name.length - 1) {
      if (b == true && p == true) {
        nameSub = name.substring(0, i - 2) + "..."
      }
      if (b == false && p == false) {
        nameSub = name.substring(0, i - 3) + "..."
      }
      if (b == true && p == false) {
        nameSub = name.substring(0, i - 2) + "..."
      }
      if (p == true) {
        nameSub = name.substring(0, i - 2) + "..."
      }
      break
    }
  }
  if (w <= maxLength) {
    return name
  }
  return nameSub
}
